/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.matrimony.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.matrimony.model.Photo;
import com.matrimony.model.PhotoModel;
import com.matrimony.model.PhotoSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Photo service. Represents a row in the &quot;matrimony_photo&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.matrimony.model.PhotoModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link PhotoImpl}.
 * </p>
 *
 * @author matrimony
 * @see PhotoImpl
 * @see com.matrimony.model.Photo
 * @see com.matrimony.model.PhotoModel
 * @generated
 */
@JSON(strict = true)
public class PhotoModelImpl extends BaseModelImpl<Photo> implements PhotoModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a photo model instance should use the {@link com.matrimony.model.Photo} interface instead.
	 */
	public static final String TABLE_NAME = "matrimony_photo";
	public static final Object[][] TABLE_COLUMNS = {
			{ "photoId", Types.BIGINT },
			{ "profileId", Types.BIGINT },
			{ "content", Types.VARCHAR },
			{ "name", Types.VARCHAR },
			{ "type_", Types.VARCHAR },
			{ "thumbnail", Types.BOOLEAN }
		};
	public static final String TABLE_SQL_CREATE = "create table matrimony_photo (photoId LONG not null primary key IDENTITY,profileId LONG,content VARCHAR(75) null,name VARCHAR(75) null,type_ VARCHAR(75) null,thumbnail BOOLEAN)";
	public static final String TABLE_SQL_DROP = "drop table matrimony_photo";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.matrimony.model.Photo"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.matrimony.model.Photo"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.matrimony.model.Photo"),
			true);
	public static long PROFILEID_COLUMN_BITMASK = 1L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Photo toModel(PhotoSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Photo model = new PhotoImpl();

		model.setPhotoId(soapModel.getPhotoId());
		model.setProfileId(soapModel.getProfileId());
		model.setContent(soapModel.getContent());
		model.setName(soapModel.getName());
		model.setType(soapModel.getType());
		model.setThumbnail(soapModel.getThumbnail());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Photo> toModels(PhotoSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Photo> models = new ArrayList<Photo>(soapModels.length);

		for (PhotoSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.matrimony.model.Photo"));

	public PhotoModelImpl() {
	}

	public long getPrimaryKey() {
		return _photoId;
	}

	public void setPrimaryKey(long primaryKey) {
		setPhotoId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_photoId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Photo.class;
	}

	public String getModelClassName() {
		return Photo.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("photoId", getPhotoId());
		attributes.put("profileId", getProfileId());
		attributes.put("content", getContent());
		attributes.put("name", getName());
		attributes.put("type", getType());
		attributes.put("thumbnail", getThumbnail());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long photoId = (Long)attributes.get("photoId");

		if (photoId != null) {
			setPhotoId(photoId);
		}

		Long profileId = (Long)attributes.get("profileId");

		if (profileId != null) {
			setProfileId(profileId);
		}

		String content = (String)attributes.get("content");

		if (content != null) {
			setContent(content);
		}

		String name = (String)attributes.get("name");

		if (name != null) {
			setName(name);
		}

		String type = (String)attributes.get("type");

		if (type != null) {
			setType(type);
		}

		Boolean thumbnail = (Boolean)attributes.get("thumbnail");

		if (thumbnail != null) {
			setThumbnail(thumbnail);
		}
	}

	@JSON
	public long getPhotoId() {
		return _photoId;
	}

	public void setPhotoId(long photoId) {
		_photoId = photoId;
	}

	@JSON
	public long getProfileId() {
		return _profileId;
	}

	public void setProfileId(long profileId) {
		_columnBitmask |= PROFILEID_COLUMN_BITMASK;

		if (!_setOriginalProfileId) {
			_setOriginalProfileId = true;

			_originalProfileId = _profileId;
		}

		_profileId = profileId;
	}

	public long getOriginalProfileId() {
		return _originalProfileId;
	}

	@JSON
	public String getContent() {
		if (_content == null) {
			return StringPool.BLANK;
		}
		else {
			return _content;
		}
	}

	public void setContent(String content) {
		_content = content;
	}

	@JSON
	public String getName() {
		if (_name == null) {
			return StringPool.BLANK;
		}
		else {
			return _name;
		}
	}

	public void setName(String name) {
		_name = name;
	}

	@JSON
	public String getType() {
		if (_type == null) {
			return StringPool.BLANK;
		}
		else {
			return _type;
		}
	}

	public void setType(String type) {
		_type = type;
	}

	@JSON
	public boolean getThumbnail() {
		return _thumbnail;
	}

	public boolean isThumbnail() {
		return _thumbnail;
	}

	public void setThumbnail(boolean thumbnail) {
		_thumbnail = thumbnail;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Photo.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Photo toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Photo)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		PhotoImpl photoImpl = new PhotoImpl();

		photoImpl.setPhotoId(getPhotoId());
		photoImpl.setProfileId(getProfileId());
		photoImpl.setContent(getContent());
		photoImpl.setName(getName());
		photoImpl.setType(getType());
		photoImpl.setThumbnail(getThumbnail());

		photoImpl.resetOriginalValues();

		return photoImpl;
	}

	public int compareTo(Photo photo) {
		long primaryKey = photo.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Photo photo = null;

		try {
			photo = (Photo)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = photo.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		PhotoModelImpl photoModelImpl = this;

		photoModelImpl._originalProfileId = photoModelImpl._profileId;

		photoModelImpl._setOriginalProfileId = false;

		photoModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Photo> toCacheModel() {
		PhotoCacheModel photoCacheModel = new PhotoCacheModel();

		photoCacheModel.photoId = getPhotoId();

		photoCacheModel.profileId = getProfileId();

		photoCacheModel.content = getContent();

		String content = photoCacheModel.content;

		if ((content != null) && (content.length() == 0)) {
			photoCacheModel.content = null;
		}

		photoCacheModel.name = getName();

		String name = photoCacheModel.name;

		if ((name != null) && (name.length() == 0)) {
			photoCacheModel.name = null;
		}

		photoCacheModel.type = getType();

		String type = photoCacheModel.type;

		if ((type != null) && (type.length() == 0)) {
			photoCacheModel.type = null;
		}

		photoCacheModel.thumbnail = getThumbnail();

		return photoCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(13);

		sb.append("{photoId=");
		sb.append(getPhotoId());
		sb.append(", profileId=");
		sb.append(getProfileId());
		sb.append(", content=");
		sb.append(getContent());
		sb.append(", name=");
		sb.append(getName());
		sb.append(", type=");
		sb.append(getType());
		sb.append(", thumbnail=");
		sb.append(getThumbnail());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(22);

		sb.append("<model><model-name>");
		sb.append("com.matrimony.model.Photo");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>photoId</column-name><column-value><![CDATA[");
		sb.append(getPhotoId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>profileId</column-name><column-value><![CDATA[");
		sb.append(getProfileId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>content</column-name><column-value><![CDATA[");
		sb.append(getContent());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>name</column-name><column-value><![CDATA[");
		sb.append(getName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>type</column-name><column-value><![CDATA[");
		sb.append(getType());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>thumbnail</column-name><column-value><![CDATA[");
		sb.append(getThumbnail());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Photo.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Photo.class
		};
	private long _photoId;
	private long _profileId;
	private long _originalProfileId;
	private boolean _setOriginalProfileId;
	private String _content;
	private String _name;
	private String _type;
	private boolean _thumbnail;
	private long _columnBitmask;
	private Photo _escapedModelProxy;
}